package pms.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import pms.dao.EventDao;
import pms.dto.EventTheaterDTO;


/** 
 * <p>
 * Controller to generate the Home Page basics to be rendered by a view. 
 * It extends the convenience class AbstractController that encapsulates most 
 * of the drudgery involved in handling HTTP requests. 
 * </p>
 * 
 * <p>
 * ModelAndView contains
 * <ul>
 * <li>title: Will be used as a headline in the resulting view</li>
 * <li>message: Some hints for the user</li>
 * </ul>
 * The name of the selected view will be: 'list-events.jsp'.
 * </p>
 * 
 * @see eventDao
 * @author KRS DEV Team (krsdevteam@PMSWIbb2011SS.de)
 */
public class AlleEvents extends AbstractController {
    private static Log log = LogFactory.getLog(AlleEvents.class);
	private EventDao eventDao;

	public void setEventDao(EventDao eventDao) {
		this.eventDao = eventDao;
	}
	
	public EventDao getEventDao() {
		return eventDao;
	}

	protected ModelAndView handleRequestInternal(
			HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse) throws Exception {
		log.info(httpServletRequest.getPathTranslated());		
		ModelAndView mv = new ModelAndView();
		mv.addObject("privileged", httpServletRequest.isUserInRole("admin"));
		mv.addObject("title", "Liste der Veranstaltungen");
		mv.addObject("message", "Bisher eingetragene Veranstaltungen:");
		List<EventTheaterDTO> ev = eventDao.findAllET();
		mv.addObject("events", ev);
		mv.addObject("edit", false);
		mv.setViewName("list-events");
		return mv;
		
	}

}
